package cn.gson.crm.controller;


import cn.gson.crm.model.pojos.*;
import cn.gson.crm.model.service.UserService;
import cn.gson.crm.model.service.WarehousingService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/UserController")
public class UserController {
    @Autowired
    UserService service;
    @RequestMapping("/ContractMethod")
    @ResponseBody
    //查询所有员工
    public Map<String,Object> selectuser(Integer page, Integer size){

        return service.selectuser(page,size);
    };
    @RequestMapping("/ContractMethod2")
    @ResponseBody
    //根据部门查询职位
    public List<Role> selectrow(Integer did){
        return service.selectrow(did);
    };
    @RequestMapping("/ContractMethod3")
    @ResponseBody
    //修改员工为离职状态
    public void updateyuan(Integer yid){
        service.updateyuan(yid);
    };
    @RequestMapping("/ContractMethod4")
    @ResponseBody
    //根据员工id查询员工详情
    public List<User>  selectuserxiang(Integer yid){
        return   service.selectuserxiang(yid);
    };
    @RequestMapping("/ContractMethod5")
    @ResponseBody
    //条件查询员工
    public Map<String,Object> selectwhere(String where,Integer page, Integer size){
        return service.selectwhere(where,page,size);
    };
    @RequestMapping("/ContractMethod6")
    @ResponseBody
    public Map<String,Object> selectDate( String statr,  String endtime,Integer page, Integer size){
        return service.selectDate(statr,endtime,page,size);
    };
    @RequestMapping("/ContractMethod7")
    @ResponseBody
    //新增员工
    public void saveuser(@RequestBody User user){
       service.saveuser(user);
    }
    @RequestMapping("/ContractMethod8")
    @ResponseBody
    //查询员工根据姓名
    public List<User> selectyname(String yname){
        return service.selectyname(yname);
    };
    @RequestMapping("/ContractMethod9")
    @ResponseBody
    //登录查看是否存在
    public List<User> selectfoucun(String yname, String ypass, HttpSession session){
        List<User> userList=service.selectfoucun(yname,ypass);
        if(!userList.isEmpty()){
            session.setAttribute("login",userList.get(0));
        }
        return service.selectfoucun(yname,ypass);
    };
    @RequestMapping("/ContractMethod10")
    @ResponseBody
    public Map<String,Object> userFunction(Integer uid){
        //Employeer emp = (Employeer) session.getAttribute("login");
        Map<String,Object> map=new HashMap<>();
        //System.err.println("id"+emp.getEmpId());
     map.put("children",service.selectFonks(uid));
    map.put("sonFuns",service.selectFonks(uid));
        map.put("faFun",service.faFun(uid));
        return map;
    }
    //按钮查询
    @RequestMapping("/ContractMethod11")
    @ResponseBody
    public List<String> selectanniu(Integer uid){
        return service.selectanniu(uid);
    };
}
